package com.qf.oa_system.util;

import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

/**
 * Created by IntelliJ IDEA.
 *
 * @author : YanCongFei
 * @date : 2020/6/9 16:09
 */
public class FtpFileUpload {
    public static void uploadHeadPic(String filename,FileInputStream fileInputStream) throws IOException {

        //	创建FTP连接z
        FTPClient ftpClient = new FTPClient();
        //	登陆ftp服务器
        ftpClient.connect("39.97.124.153", 21);
        ftpClient.login("ftpuser", "123456");
        //	上传文件
        //	读取本地文件,FileInputStream
        //	设置保存路径
        ftpClient.enterLocalPassiveMode();
        ftpClient.changeWorkingDirectory("images");
        ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
        ftpClient.storeFile(filename, fileInputStream);
        //	关闭连接
        ftpClient.logout();

    }
}
